package com.qianxunclub.chapter6;


import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;

public class AtomicDemo {


    public static void main(String[] args) throws Exception {
        AtomicInteger atomicInteger = new AtomicInteger(0);
        AtomicReference<Integer> num = new AtomicReference<>(0);

        for (int i = 0; i < 100; i++) {
            Thread thread = new Thread(() -> {
                for (int j = 0; j < 100; j++) {
                    int r = atomicInteger.incrementAndGet();
                    num.set(num.get() + 1);
                    int rr = num.get();
                    System.out.println("atomicInteger:" + r);
                    System.out.println("num:" + rr);
                }
            });
            thread.start();
        }
    }
}
